package com.haochang.chunkvod.tools.vod.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author qintao
 *         created at 2016/9/14 17:11
 *         单列线程池管理类
 */

public class ThreadPoolUtil {
    /**
     * 每次只执行一个任务的线程池
     */
    private static ExecutorService singleTaskExecutor = null;

    /**
     * 每次只执行一个线程任务的线程池
     * 限制最大线程数的线程池 一个
     * Executors.newSingleThreadExecutor()
     */
    public static ExecutorService getInstanceSingleTaskExecutor() {
        if (null == singleTaskExecutor) {
            synchronized (ThreadPoolUtil.class) {
                if (null == singleTaskExecutor) {
                    singleTaskExecutor = Executors.newSingleThreadExecutor();// 每次只执行一个线程任务的线程池
                }
            }
        }
        return singleTaskExecutor;
    }
}
